package org.example.servicemanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.model.student.bean.Task;
import org.example.servicemanage.mapper.TaskMapper;
import org.example.servicemanage.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-08-03
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {

    @Autowired
    private TaskMapper taskMapper;

    @Override
    public List<Task> getByMajorId(Integer majorId) {
        return taskMapper.selectList(new QueryWrapper<Task>().eq("major_id", majorId));
    }

    @Override
    public int changeTask(Task task) {
        task.setUpdateTime(LocalDateTime.now());
        return taskMapper.updateById(task);
    }

    @Override
    public int deleteTask(Integer majorId, Integer taskId) {
        return taskMapper.delete(new QueryWrapper<Task>().eq("major_id", majorId).eq("task_id", taskId));
    }
}
